#ifndef KEYBOARD_HPP
#define KEYBOARD_HPP
#include <stdint.h>
#include <stdbool.h>
#include "gpio.hpp"

using namespace device;
#define KEYBOARD_MAX_SUPPORT		16

#define KEY_STATUS_ACTIVELOW							0x01
#define KEY_STATUS_REPEATENABLE						0x02
#define KEY_STATUS_LONGPRESSENABLE				0x04
#define KEY_STATUS_PRESSSTATUS						0x10
#define KEY_STATUS_PRESSSTATUS_BACK				0x20
#define KEY_STATUS_LONGPRESSSTATUS				0x40
#define KEY_STATUS_LONGPRESSSTATUS_BACK		0x80

namespace ui
{
	class key
	{
		private:
			gpio::GpioPinTPDF mGpioPin;
			uint8_t mStatus;
			uint32_t mPressPeriod;
			uint32_t mLongPressPeriod;
			uint32_t mCount;
			uint32_t mLongCount;
			static bool mKeyboardInit;
			static key* mKey[KEYBOARD_MAX_SUPPORT];
			static bool StatusTimerTick(void);
		
		public:
			typedef enum
			{
				KEY_EVENT_TYPE_NONE = 0,
				KEY_EVENT_TYPE_PRESS,
				KEY_EVENT_TYPE_LONGPRESS,
			}KeyEventTypeTPDF;
			
			typedef void (*KeyEventDelegate)(key *tTag, KeyEventTypeTPDF tKeyEventType);
			uint8_t KeyIndex;
			
			key(uint8_t ucKeyIndex, gpio::GpioPortTPDF tGpioPort, uint8_t ucGpioPin, bool bActiveLow, uint32_t uiPressPeriod, bool bRepeat);
			key(uint8_t ucKeyIndex, gpio::GpioPortTPDF tGpioPort, uint8_t ucGpioPin, bool bActiveLow, uint32_t uiPressPeriod, bool bRepeat, uint32_t uiLongPressPeriod);
			~key();
			bool Pressed(void);
			bool LongPressed(void);
			static KeyEventDelegate KeyEventCallBack;
			static bool Register(key *tKey);
	};
	class keyboard
	{
	};
}
#endif
